import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import path from 'path'

export const routes = [
  {
    path: '/BasicData',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'Product',
        component: () => import('@/views/BasicData/Products'),
        meta: { title: '产品管理', icon: 'el-icon-s-shop' }
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/Login/index'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/workbench'
  },
  {
    path: '/workbench',
    component: () => import('@/views/Workbench/index'),
    meta: { title: '工作台', icon: 'el-icon-data-board' }

  },
  // {
  //   path: '/workbench',
  //   component: Layout,
  //   children: [{
  //     path: '',
  //     component: () => import('@/views/Workbench/index'),
  //     meta: { title: '工作台', icon: 'el-icon-data-board' }
  //   }]
  // },
  {
    path: '/purchases',
    component: Layout,
    permission: 'purchases',
    meta: { title: '采购管理', icon: 'el-icon-office-building' },
    children: [{
      path: 'preorder',
      permission: 'purchases:purchases',
      meta: { title: '采购订单' },
      component: () => import('@/views/Purchases/PurchasesOrders/index.vue')
    },
    {
      path: 'in',
      permission: 'purchases:in',
      meta: { title: '采购入库' },
      component: () => import('@/views/Purchases/PurchasesIn/index')
    },
    {
      path: 'returns',
      permission: 'purchases:returns',
      meta: { title: '采购退货' },
      component: () => import('@/views/Purchases/PurchasesReturns/index')
    }]
  },
  {
    path: '/display',
    permission: 'display',
    meta: { title: '采购数据展示' },
    component: () => import('@/views/Purchases/DataDisplay/index')
  },

  {
    path: '/sales',
    component: Layout,
    permission: 'sales',
    meta: { title: '销售管理', icon: 'el-icon-guide' },
    children: [{
      path: 'presales',
      permission: 'sales:presales',
      component: () => import('@/views/Sales/PreSales'),
      meta: { title: '销售订单' }
    }, {
      path: 'orders',
      permission: 'sales:orders',
      component: () => import('@/views/Sales/SalesOrder'),
      meta: { title: '销售出库' }
    }, {
      path: 'returns',
      permission: 'sales:returns',
      component: () => import('@/views/Sales/SalesReturns'),
      meta: { title: '销售退货' }
    },
    {
      path: 'other',
      permission: 'sales:other',
      component: () => import('@/views/Sales/OtherSales'),
      meta: { title: '其他销售' }
    }]
  },
  {
    path: '/stock',
    component: Layout,
    permission: 'stock',
    meta: { title: '库存管理', icon: 'el-icon-refrigerator' },
    children: [{
      path: 'manage',
      permission: 'stock:manage',
      component: () => import('@/views/Stock/StockManage'),
      meta: { title: '预盘点单' }
    }, {
      path: 'count',
      permission: 'stock:count',
      component: () => import('@/views/Stock/InventoryCounts'),
      meta: { title: '库存盘点' }
    }]
  },
  {
    path: '/sys',
    component: Layout,
    permission: 'sys',
    meta: { title: '系统管理', icon: 'el-icon-setting' },
    children: [{
      path: 'data',
      permission: 'sys:data',
      component: () => import('@/views/System/DataManagement/index'),
      meta: { title: '资料管理' }
    }, {
      path: 'user',
      permission: 'sys:user',
      component: () => import('@/views/System/Employee/index'),
      meta: { title: '用户管理' }
    }]
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  mode: 'hash',
  scrollBehavior: () => ({ y: 0 }),
  routes: routes
})

const router = createRouter()

// 重置路由方法
export function resetRouter() {
  // 得到一个全新的router实例对象
  const newRouter = createRouter()
  // 使用新的路由记录覆盖掉老的路由记录
  router.matcher = newRouter.matcher
}

export default router
